#include <iostream>
#include <cmath>
#include "Function.hpp"
#include "EquationSolver.hpp"

const double PI = acos(-1.0);

// (C)
class F: public Function {
private:
    double A, B, C, D, E, l, h, beta_1;
public:
    F(double l, double h, double D, double beta_1) : l(l), h(h), D(D), beta_1(beta_1) {
        double beta1 = beta_1 * PI / 180.0;
        A = l * sin(beta1);
        B = l * cos(beta1);
        C = (h + 0.5 * D) * sin(beta1) - 0.5 * D * tan(beta1);
        E = (h + 0.5 * D) * cos(beta1) - 0.5 * D;
    }

    double operator()(double alpha) const {
        double alpha_rad = alpha * PI / 180.0;
        return A * sin(alpha_rad) * cos(alpha_rad) + B * sin(alpha_rad) - C * cos(alpha_rad) - E * sin(alpha_rad);
    }
};

void solve_f(double l, double h, double D, double beta_1) {
    std::cout << "Solving (c)" << std::endl;
    F f(l, h, D, beta_1);
    Secant_Method solver_f(f,60,79); // 初始猜测远离 33 度
    double alpha = solver_f.solve();
    std::cout << "A root is: " << alpha << " degrees" << std::endl;
}

int main() {
    solve_f(89, 49,30, 11.5);
    return 0;
}
